var api = require('../../utils/api.js')

Page({
    data: {
        list: [],
        top:32,
        user:[]
    },
    onLoad() {
      var info = wx.getMenuButtonBoundingClientRect();
      console.log(info);
      var that = this;
      var top = info.top;
      this.setData({
          top: top+32
      })

      api.get({
        url: 'wxapp/index/getcodes',
        data: {},
        success: data => {
          console.log(data);
          var info = data.data;
          that.setData({
            codes: info.codes
          })
        }
      });
    },
    onShow() {
        let user = wx.getStorageSync('user');
        if (!user) {
            wx.navigateTo({
                url: '/pages/login/login'
            });
        }
        var that = this;
        api.get({
          url: 'wxapp/user/getUserInfo',
          data: {},
          success: data => {
            console.log(data);
            var user = data.data;
            that.setData({
              user: user
            })
          }
        });


    
   
    },

    getqrcode(){
        api.get({
            url: 'wxapp/Getqrcode/getqrcode',
            data: {},
            success: data => {
                console.log(data.data);
            }
        });

    },

    nexturl(ret){
      console.log(ret);
      var url=ret.currentTarget.dataset.url;

      wx.navigateTo({
        url: url
      })

    },

    scanCodeEvent(ret){
      wx.scanCode({
        onlyFromCamera: true,// 只允许从相机扫码
        success(res){
          console.log(res.result);

          var code=res.result;

          api.get({
            url: 'wxapp/user/ruku',
            data: {code:code},
            success: data => {
                console.log(data.data);

                wx.showToast({
                  title: data.msg,
                  icon:'none'
                })


            }
          });
   
          
     
        }
      })
  
    },

    getdesc(ret){
      console.log(ret);

      var value=ret.detail.value;

      api.get({
        url: 'wxapp/user/signature',
        data: {value:value},
        success: data => {
            console.log(data.data);
        }
      });



    },


    tames(){
        
        var tamecodes=wx.getStorageSync('tamecodes');
        var codes=this.data.codes;


        if(!tamecodes){
            wx.showModal({
                editable:true,//显示输入框
                placeholderText:'请输入验证码',//显示输入框提示信息
                success: res => {
                  if (res.confirm) { //点击了确认


                    var content=res.content;

                    if(content==codes){

                        wx.setStorageSync('tamecodes', content)
                        wx.navigateTo({
                          url: '/pages/my/tameorder',
                        })
                    }else{
                        wx.showToast({
                          title: '输入错误',
                          icon:'none'
                        })
                    }


                   
                  } 
                }
              })

        }else{
            wx.navigateTo({
                url: '/pages/my/tameorder',
              })
        }

  
      


    }
});